
import axios from '@ohos/axios'
import Account from '../viewModel/Account'
import AccountType from '../viewModel/AccountType'
import Budget from '../viewModel/Budget'
import Properly from '../viewModel/Properly'
import User from '../viewModel/User'
// let baseUrl= '10.2.2.108'
let baseUrl= '192.168.43.254'
class ProperlyModel{
  //查询
  getBudgetList():Promise<Properly[]>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'GET',
        // url:'http://localhost:8080/properly/listProperly',
        url:'http://'+baseUrl+':8080/properly/listProperly',
        params:{
          uid:AppStorage.Get('uid')
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('查询失败')
      })
    })
  }
  //删除
  deleteRecord(properly:Properly):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/properly/deleteProperly',
        url:'http://'+baseUrl+':8080/properly/deleteProperly',
        data:{
          uid:AppStorage.Get('uid'),
          pid:properly.pid,
          pname:properly.pname,
          price:properly.price,
          type:properly.type,
          isdelete:properly.isdelete
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }
  //新增
  insertBudget(properly:Properly):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/properly/insertProperly',
        url:'http://'+baseUrl+':8080/properly/insertProperly',
        data:{
          uid:AppStorage.Get('uid'),
          pname:properly.pname,
          price:properly.price,
          type:properly.type,
          isdelete:0
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }

  //修改
  updateRecord(properly:Properly):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/properly/updateProperly',
        url:'http://'+baseUrl+':8080/properly/updateProperly',
        data:{
          uid:AppStorage.Get('uid'),
          pname:properly.pname,
          price:properly.price,
          type:properly.type,
          isdelete:0
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }
//计算
  countProperly():Promise<number[]>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'GET',
        // url:'http://localhost:8080/properly/countProperly',
        url:'http://'+baseUrl+':8080/properly/countProperly',
        params:{
          uid:AppStorage.Get('uid')
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('查询失败')
      })
    })
  }

}
const properlyModel = new ProperlyModel();
export default properlyModel as ProperlyModel;


